import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_floating/floating/assist/Point.dart';
import 'package:flutter_floating/floating/assist/floating_slide_type.dart';
import 'package:flutter_floating/floating/floating.dart';
import 'package:flutter_floating/floating/manager/floating_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/generated/locales.g.dart';

class FloatingUtil {
  static FloatingManager floatingManager = FloatingManager();

  static void openFloating(int signal) {
    floatingManager
        .createFloating(signal,
            Floating(floatWidget(signal), moveOpacity: 1, point: Point(100.w, 100.h), slideType: FloatingSlideType.onPoint, isStartScroll: false))
        .open(Get.overlayContext!);
    Future.delayed(const Duration(milliseconds: 100), () {
      for (var i = 0; i < 5; i++) {
        if (i != signal) {
          floatingManager.closeFloating(i);
        }
      }
    });
  }

  static closeAllFloating() {
    floatingManager.closeAllFloating();
  }

  static Widget floatWidget(int signal) {
    return Container(
      margin: EdgeInsets.all(38.w),
      width: 1.sw - 280.w,
      height: 180.h,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.center,
          end: Alignment.center,
          colors: Platform.isAndroid ? [Colors.white38, Colors.black38] : [Colors.black45, Colors.black],
        ),
        borderRadius: BorderRadius.circular(10),
        // boxShadow: const [
        //   BoxShadow(
        //       color: Colors.black12,
        //       offset: Offset(0.0, 15.0), //阴影xy轴偏移量
        //       blurRadius: 15.0, //阴影模糊程度
        //       spreadRadius: 1.0 //阴影扩散程度
        //       )
        // ],
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          SizedBox(width: 100.w),
          Text(signal <= 0 ? LocaleKeys.sports_positioning_text.ts : LocaleKeys.sports_in_motion_text.ts,
              style: TextStyle(color: Colors.white, fontSize: 49.sp, decoration: TextDecoration.none)),
          const Spacer(),
          if (signal > 0)
            Row(
              children: [
                Text('GPS', style: TextStyle(color: Colors.white, fontSize: 49.sp, decoration: TextDecoration.none)),
                SizedBox(width: 10.w),
                Image.asset('assets/images/sports/icon_gps_$signal.png', width: 85.w, height: 46.h, color: Color.fromRGBO(29, 96, 204, 1.0)),
              ],
            ),
          SizedBox(width: 100.w),
        ],
      ),
    );
  }
}
